<?php
require '../connect/connect.php';
$page='main_forum';
include_once 'header.php';
$tbl_name = "forum_question"; // Table name
extract($_POST);
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}


$sql = "SELECT * FROM $tbl_name WHERE id='$id'";
$result = mysql_query($sql);

$rows = mysql_fetch_array($result);
?>
<div id="content"><div>
<!--        <button style="width: 50%;"><a href="main_forum.php"><< Back </a></button><button style="width: 50%"><a href="create_topic.php">Create New </a></button>-->
        <button style="width: 50%; background-color: #ffffff"><a href="main_forum.php"><< Back </a></button><button style="width: 50%; background-color: #ffffff"><a href="create_topic.php">Create New </a></button>
<!--<strong><?php echo $rows['topic'] . " (" . $rows['datetime'] . ")"; ?></strong><br/>-->
        <p style="font-weight: bold"><?php echo $rows['detail']; ?></p>
        <?php
        $tbl_name2 = "forum_answer"; // Switch to table "forum_answer"

        $sql2 = "SELECT * FROM $tbl_name2 WHERE question_id='$id'";
        $result2 = mysql_query($sql2);

        while ($rows = mysql_fetch_array($result2)) {
            ?>
        <p style="background-color: #ccccff; font-style: italic"><?php echo $rows['a_answer']; ?><?php echo " (". $rows['a_datetime'].")"; ?></p>

            <?php
        }

        $sql3 = "SELECT view FROM $tbl_name WHERE id='$id'";
        $result3 = mysql_query($sql3);

        $rows = mysql_fetch_array($result3);
        $view = $rows['view'];

// if have no counter value set counter = 1
        if (empty($view)) {
            $view = 1;
            $sql4 = "INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
            $result4 = mysql_query($sql4);
        }

// count more value
        $addview = $view + 1;
        $sql5 = "update $tbl_name set view='$addview' WHERE id='$id'";
        $result5 = mysql_query($sql5);

        mysql_close();
        ?>
        <form name="form1" method="post" action="add_answer.php">
            <strong >Comment: </strong><br/>
            <textarea name="a_answer" style="width: 99%" rows="4" id="a_answer"></textarea><input name="id" type="hidden" value="<?php echo $id; ?>"><br/>
            <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset">
        </form>

        <?php include_once 'footer.php'; ?>